package main

import (
	"fmt"
	"reflect"
)

func main() {
	stu := Student {
		Name: "张三",
		Age: 18,
	}

	testReflect(stu)

}

func testReflect(i interface{}) {

	reType := reflect.TypeOf(i)
	reValue := reflect.ValueOf(i)

	// 获取变量的类别
	kind := reType.Kind()
	fmt.Println(kind)

	kind2 := reValue.Kind()
	fmt.Println(kind2)

	// 获取变量的类型
	i2 := reValue.Interface()
	n, flag := i2.(Student)
	if flag == true {
		fmt.Printf("结构体的类型: %T \n", n)
	}

}

type Student struct{
	Name string
	Age int
}